#!/bin/bash

# Check if Maven is installed
if ! command -v mvn &> /dev/null; then
    echo "Maven is not installed. Please install Maven first."
    exit 1
fi

# Build the project
echo "Building project..."
mvn clean package

# Check if build was successful
if [ $? -ne 0 ]; then
    echo "Build failed. Please fix the errors and try again."
    exit 1
fi

# Check if input file and output directory are provided
if [ $# -lt 2 ]; then
    echo "Usage: $0 <input-ppt-file> <output-directory>"
    echo "Example: $0 presentation.pptx ./output"
    exit 1
fi

INPUT_FILE="$1"
OUTPUT_DIR="$2"

# Check if input file exists
if [ ! -f "$INPUT_FILE" ]; then
    echo "Input file does not exist: $INPUT_FILE"
    exit 1
fi

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

# Run the page-by-page demo
echo "Running page-by-page demo..."
java -cp target/jboltai_ppt_extract-1.0.0-jar-with-dependencies.jar com.jboltai.pptextract.PageByPageDemo "$INPUT_FILE" "$OUTPUT_DIR"
